﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using HalalCheck.DataModels;
using Xamarin.Forms;
using XLabs.Forms.Mvvm;

namespace HalalCheck.View
{
    public class HalalPage : BaseView
    {
        public HalalPage()
        {
            var stackl = new StackLayout
            {
                BackgroundColor = Color.Blue,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            var tc = new SearchBar
            {
                Text = "hello ali",
                BackgroundColor = Color.Lime,

            };
            tc.SetBinding(SearchBar.TextProperty,new Binding("Search"));

            var listhalal = new ListView
            {
                VerticalOptions = LayoutOptions.FillAndExpand,

            };
            listhalal.SetBinding(ListView.ItemsSourceProperty, new Binding("HalalListFiltered"));
            //  listhalal.SetBinding(ListView.SelectedItemProperty, new Binding("SelectedItem", BindingMode.TwoWay));
            listhalal.ItemSelected += (sender, e) =>
            {
                if (e.SelectedItem == null)
                    return; // don't do anything if we just de-selected the row
                // do something with e.SelectedItem
                ((ListView)sender).SelectedItem = null; // de-select the row
            };
            //  _dealListView.RowHeight = (int)(Rowheight);
            listhalal.ItemTemplate = new DataTemplate(() =>
            {
                var itemLayout = new RelativeLayout
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions = LayoutOptions.FillAndExpand,
                };

                var label = new Label
                {

                };
                label.SetBinding(Label.TextProperty, new Binding("Id"));
                label.SetBinding(Label.BackgroundColorProperty,new Binding("HalalColor"));

                itemLayout.Children.Add(label, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent((parent) => parent.Bounds.Width), Constraint.RelativeToParent((parent) => parent.Bounds.Height));


                return new ViewCell
                {
                    View = itemLayout
                };
            });
            listhalal.HasUnevenRows = false;
            listhalal.RowHeight = 50;


            stackl.Children.Add(tc);
            stackl.Children.Add(listhalal);
            Content = stackl;
        }
    }
}
